<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/include/taglib.jsp"%>
<html>
<head>
<meta charset="UTF-8">
<title>我的账户-账户验证|验证手机</title>
<jsp:include page="/include/wchat/head.jsp"></jsp:include>
<link type="text/css" rel="stylesheet" href="/v2/wchat/resrc/css/account.css">
</head>
<body>
<div id="header"> <a href="javascript:history.go(-1);" class="backto">返回</a>
  <div class="title-sub">验证账户信息</div>
</div>
<div id="wrap">
  <div class="phoneBind2">
    <div class="link-touch">
      <ul class="items">
        <li> <span class="txt">手机</span> <span class="value">${b_mobile}</span><a href="javascript:changeMobile()"  id="change" class="btn btn-verify">修改</a> </li>
        <li>
          <label class="txt">验证</label>
          <input type="text" class="input" id="verifyCode" name="vierifyCode" maxlength="6" placeholder="请确认短信验证码">
          <input type="hidden" id="mobile" name="mobile" value="${b_mobile}" />
          <%--<a href="javascript:choose();"  id="chooseA" class="btn btn-verify">获取验证码</a> --%>
          <a href="javascript:;" id="chooseA" class="btn btn-verify" onclick="return getMobileCode(1)">获取验证码</a> 
        </li>
      </ul>
      <div class="vtip errs" id="vTip"></div>
    </div>
    <div class="link-touch">
      <ul class="items">
        <li>
          <label class="txt">支付密码</label>
          <input type="password" id="payPwd" name="payPwd" class="input" maxlength="16" placeholder="请输入支付密码" >
        </li>
      </ul>
      <div class="vtip errs" id="pTip"></div>
    </div>
        <div id="chooseCodeTypeDiv" class="tips-type none"> 请选择获取验证码的方式：
			<div class="type">
				<a class="btn fl" href="javascript:;" onclick="return getMobileCode(1);">短信获取</a>
				<a class="btn fr" href="javascript:;" onclick="return getMobileCode(2);">电话获取</a>
	   </div>
    </div>
    <div class="itip" id="eTip">如果您没有修改过支付密码，则您的支付密码与您初次设置的登录密码一致。 </div>
    <div class="operate-button operate-acc"> <a href="javascript:bindMobile();" class="btn">验证手机号</a></div>
  </div>
</div>

<jsp:include page="/include/wchat/footer.jsp"></jsp:include>

<script type="text/javascript">
$(function(){
	//倒计时
	_interval = setInterval("smsSend()", 1000);
});
var n =60;
var _interval;
function smsSend(){
	n--;
	//获取验证码按钮不可用
	$("#chooseA").addClass("btn-resend");
	$("#chooseA").removeAttr("onclick");
	$("#chooseA").html(n + "秒后重发");
	$("#chooseCodeTypeDiv").hide();
	
	if(n == 0){
		$("#chooseA").removeClass("btn-resend");
		$("#chooseA").attr("onclick","return getMobileCode(1);");
		$("#chooseA").html("获取验证码");
		clearInterval(_interval);
		n = 60;
	}
}

function choose() {
	if(!$("#chooseA").hasClass("btn-resend")){
		$("#chooseCodeTypeDiv").show();
	}
}

function getMobileCode(type){
	var mobileNum = $('#mobile').val();
	if(mobileNum == "" || mobileNum == null){
		$("#vTip").html("请输入手机号").show();
		return false;
	}
	if(!(/^((13[0-9])|(15[^4,\D])|(17[0678])|(18[0-9]))\d{8}$/.test(mobileNum))){
		$("#vTip").html("手机号格式不正确，请检查").show();
		$("#change").focus();
        return false;
    }
	if (type != 1 && type != 2) {
    	$("#eTip").html('获取验证码失败，请刷新页面后重试').show();
    	return false;
	}
	$.ajax({
		Type: 'POST',
		url:  "/getMoblieVerifyCode.do",
		data: {"mobileNum": mobileNum} ,
		success:function(data){
			if(data.code < 0){
				$("#eTip").html(data.msg).show();
				return false;
			}
			_interval = setInterval("smsSend()", 1000);
		}
	});
}

function bindMobileCheck(){
	var mobileNum = $('#mobile').val();
	if(mobileNum == "" || mobileNum == null){
		$("#vTip").html("请输入手机号").show();
		return false;
	}
	if(!(/^((13[0-9])|(15[^4,\D])|(17[0678])|(18[0-9]))\d{8}$/.test(mobileNum))){
		$("#vTip").html("手机号格式不正确，请检查").show();
		$("#change").focus();
        return false;
    }
	if($("#verifyCode").val() == ""){
		$("#vTip").html("请输入验证码").show();
		return false;
	}
	if($("#payPwd").val() == ""){
		$("#pTip").html("请输入支付密码").show();
		return false;
	}
	return true;
}

function bindMobile(){
	var mobileNum = $('#mobile').val();
	if(!bindMobileCheck()){
		return ;
	}else{
		var param = {};
	    param["paramMap.mobileNum"] = mobileNum;
	    param["paramMap.verifyCode"] = $("#verifyCode").val();
	    param["paramMap.payPwd"] = $("#payPwd").val();
		$.ajax({
			Type: 'POST',
			url: "/bindMobileWithVerifyCode.do" ,
			data: param ,
			beforeSend:function(){
				
			},
			success:function(data){
				if(data.code <0){
					if(data.code == -1 || data.code == -3 || data.code== -4 ||data.code == -8){
						$("#vTip").html(data.msg).show();
					}else{
						$("#pTip").html(data.msg).show();
					}	
				}else if(data.code == 1){
					window.location.href="/bindMobileSuccess.do";
				}
			},
			error:function(){
				$("#pTip").html("用户绑定手机失败，请重新操作").show();
			}
		});
	}
}

function changeMobile(){
	var mobileNum = $('#mobile').val();
	window.location.href = "/bindMobile.do?mobileNum=" +mobileNum ;
}
</script>
</body>
</html>